<template>
	<el-dialog  draggable overflow v-model="visible" :title="titleMap[mode]" :width="800" destroy-on-close @closed="$emit('closed')">


		<!-- <sc-water-mark ref="wm" text="已审核" subtext="誉卓纱线"> -->
		<sk-tabs type="border-card">
			<el-tab-pane label="附件">
				<sk-upload v-model="form.attachments" :limit="10" draggable tip="单个文件不要超过10M,请上传图像格式文件"
					:allow_delete="false">
				</sk-upload>
			</el-tab-pane>
		</sk-tabs>
		<!-- </sc-water-mark> -->
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ["success", "closed"],
	components: {

	},
	data() {
		return {
			mode: "add",

			titleMap: {
				add: "新增",
				edit: "编辑",
			},
			form: {
				attachments: [],
			},

			visible: false,
			isSaveing: false,
		};
	},
	mounted() {
	},
	methods: {

		//显示
		open(mode = "add") {
			this.mode = mode;

			this.visible = true;

			return this;
		},

		//表单提交方法
		submit() {

			this.isSaveing = true;

			this.$API.purchase.storage.uploadAttachment.post(
				this.form
			).then((res) => {
				if (res.code == 200) {

					this.$emit("success", this.form, this.mode);
					this.visible = false;
					this.$message.success("操作成功");
				}
			}).finally(() => {
				this.isSaveing = false;
			});


		},

		//表单注入数据
		async setData(data) {
			for (let i in data) {
				if (data[i] === null) delete data[i];
			}
			delete data.details;
			Object.assign(this.form, data);
		},
	},
};
</script>

<style>
.addicon .el-select {
	width: calc(100% - 24px);
}

.addicon .el-input__wrapper {
	border-top-right-radius: 0px;
	border-bottom-right-radius: 0px;
}

.addicon .el-button--small {
	border-top-left-radius: 0px;
	border-bottom-left-radius: 0px;
}
</style>
